<!DOCTYPE html>
<html lang="ch">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Needingcen's Private TV Show</title>
    <style>
        :root {
            --bg-primary: #f9f9f9;
            --bg-secondary: #e9ecef;
            --text-primary: #333;
            --text-secondary: #6c757d;
            --card-bg: #fff;
            --card-shadow: rgba(0, 0, 0, 0.1);
            --link-color: #EC6F2F;
            --link-hover: #a1591a;
            --video-bg: #fff;
            --video-title: #343a40;
            --nav-bg: #d6d6d6;
            --list-bg: #f1f1f1;
            --list-hover: #f8f9fa;
            --container-bg: #f8f9fa;
            --folder-name-color: #18191c;
        }

        :root[data-theme="dark"] {
            --bg-primary: #1a1a1a;
            --bg-secondary: #2d2d2d;
            --text-primary: #ffffff;
            --text-secondary: #cccccc;
            --card-bg: #333333;
            --card-shadow: rgba(255, 255, 255, 0.1);
            --link-color: #ff8f4c;
            --link-hover: #ff6b1a;
            --video-bg: #2d2d2d;
            --video-title: #ffffff;
            --nav-bg: #2d2d2d;
            --list-bg: #333333;
            --list-hover: #404040;
            --container-bg: #2d2d2d;
            --folder-name-color: #ffffff;
        }

        /* Reset and base styling */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Arial', 'Helvetica Neue', Helvetica, sans-serif;
            background-color: var(--bg-primary);
            color: var(--text-primary);
            line-height: 1.6;
        }

        .container {
            max-width: 1800px;
            margin: 0 auto;
            padding: 30px 20px;
        }

        h1 {
            text-align: center;
            font-size: 2.5rem;
            color: var(--video-title);
            margin-bottom: 25px;
            text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
        }

        /* Navigation Bar */
        nav {
            background: var(--nav-bg);
            color: var(--text-dark);
            padding: 10px 20px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
        }
        .nav-links {
            display: flex;
            gap: 20px;
            align-items: center;
        }

        .nav-links a {
            color: var(--text-primary);
            text-decoration: none;
            padding: 8px 16px;
            border-radius: 5px;
            transition: background-color 0.3s ease;
        }

        .nav-links a:hover {
            background-color: var(--link-hover);
            color: #fff;
        }
        .brand-name {
            display: flex;
            align-items: center;
            gap: 15px;
            font-size: 1.8rem;
            font-weight: 700;
            color: var(--video-title);
        }

        .main-content {
            display: flex;
            gap: 20px;
            justify-content: space-between;
            margin-top: 20px;
        }

        /* Video List */
        .video-list {
            flex: 0 0 23%;
            max-height: calc(100vh - 200px);
            overflow-y: auto;
            scrollbar-width: thin;
            scrollbar-color: var(--primary-color) #EC6F2F;
        }

        /* Video Player */
        .video-player-container {
            flex: 0 0 75%;
            background: var(--video-bg);
            border-radius: 10px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
            padding: 20px;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            min-height: 500px;
        }

        .video-list::-webkit-scrollbar {
            width: 8px;
        }

        .video-list::-webkit-scrollbar-track {
            background: var(--list-bg);
            border-radius: 4px;
        }

        .video-list::-webkit-scrollbar-thumb {
            background: var(--primary-color);
            border-radius: 4px;
        }

        .video-list::-webkit-scrollbar-thumb:hover {
            background: #b3ada0;
        }

        /* Video List */
        .video-list {
            background: var(--video-bg);
            border-radius: 10px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
            padding: 15px;
            list-style: none;
            display: grid;
            grid-gap: 15px;
        }

        .video-list h3 {
            cursor: pointer;
            font-size: 1.4rem;
            color: var(--primary-color);
            display: flex;
            align-items: center;
            padding: 10px;
            background: var(--list-bg);
            border-radius: 5px;
        }

        .video-list h3 span {
            margin-right: 10px;
            font-weight: bold;
            color: var(--video-title);
            transition: all 0.3s;
        }

        .video-list h3:hover span {
            transform: rotate(45deg);
        }

        .video-list ul {
            list-style-type: none;
            margin: 0;
            padding: 0;
        }

        .video-list li {
            margin: 10px 0;
            padding: 12px 15px;
            background: var(--card-bg);
            border-radius: 8px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
            transition: all 0.3s ease;
        }

        .video-list li:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
            background: var(--list-hover);
        }

        .video-list a {
            color: var(--text-light);
            text-decoration: none;
            font-size: 1.1em;
            display: block;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

        #video-player {
            width: 100%;
            max-width: 100%;
            height: auto;
            aspect-ratio: 16/9;
            border-radius: 10px;
            box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
            margin-top: 10px;
            background-color: black;
        }

        .video-title {
            font-size: 24px;
            color: var(--video-title);
            text-align: left;
            margin: 0 0 5px 20px;
            padding: 12px 20px;
            padding-left: 0px;
            padding-bottom: 0px;
            width: fit-content;
            border-radius: 5px;
            align-self: flex-start;
        }

        .loader {
            display: none;
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            width: 50px;
            height: 50px;
            border: 5px solid #f3f3f3;
            border-top: 5px solid var(--primary-color);
            border-radius: 50%;
            animation: spin 1s linear infinite;
        }

        @keyframes spin {
            0% { transform: translate(-50%, -50%) rotate(0deg); }
            100% { transform: translate(-50%, -50%) rotate(360deg); }
        }

        @media (max-width: 768px) {
            .main-content {
                flex-direction: column;
            }

            .video-list,
            .video-player-container {
                flex: 1;
                width: 100%;
            }

            .video-list {
                max-height: 300px;
            }
        }
    </style>
</head>
<body>
    <button class="theme-toggle" id="theme-toggle" aria-label="Toggle theme" style="position: fixed; top: 20px; right: 20px; padding: 10px; background: var(--card-bg); border: none; border-radius: 50%; cursor: pointer; box-shadow: 0 2px 4px var(--card-shadow); z-index: 1000;">
        <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" style="fill: var(--text-primary);">
            <path class="sun" d="M12 2.25a.75.75 0 01.75.75v2.25a.75.75 0 01-1.5 0V3a.75.75 0 01.75-.75zM7.5 12a4.5 4.5 0 119 0 4.5 4.5 0 01-9 0zM18.894 6.166a.75.75 0 00-1.06-1.06l-1.591 1.59a.75.75 0 101.06 1.061l1.591-1.59zM21.75 12a.75.75 0 01-.75.75h-2.25a.75.75 0 010-1.5H21a.75.75 0 01.75.75zM17.834 18.894a.75.75 0 001.06-1.06l-1.59-1.591a.75.75 0 10-1.061 1.06l1.59 1.591zM12 18a.75.75 0 01.75.75V21a.75.75 0 01-1.5 0v-2.25A.75.75 0 0112 18zM7.758 17.303a.75.75 0 00-1.061-1.06l-1.591 1.59a.75.75 0 001.06 1.061l1.591-1.59zM6 12a.75.75 0 01-.75.75H3a.75.75 0 010-1.5h2.25A.75.75 0 016 12zM6.697 7.757a.75.75 0 001.06-1.06l-1.59-1.591a.75.75 0 00-1.061 1.06l1.59 1.591z"/>
        </svg>
    </button>
    <nav>
        <div class="brand-name">
            <img src="../static/logo.png" alt="logo" style="height: 60px; filter: drop-shadow(2px 2px 4px rgba(0,0,0,0.1))">
            <p>
                Hacktb Media
            </p>
        </div>
        <div class="nav-links">
            <a href="/">主页</a>
            <button class="theme-toggle" id="theme-toggle" aria-label="Toggle theme" style="padding: 10px; background: var(--card-bg); border: none; border-radius: 50%; cursor: pointer; box-shadow: 0 2px 4px var(--card-shadow);">
                <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" style="fill: var(--text-primary);">
                    <path class="sun" d="M12 2.25a.75.75 0 01.75.75v2.25a.75.75 0 01-1.5 0V3a.75.75 0 01.75-.75zM7.5 12a4.5 4.5 0 119 0 4.5 4.5 0 01-9 0zM18.894 6.166a.75.75 0 00-1.06-1.06l-1.591 1.59a.75.75 0 101.06 1.061l1.591-1.59zM21.75 12a.75.75 0 01-.75.75h-2.25a.75.75 0 010-1.5H21a.75.75 0 01.75.75zM17.834 18.894a.75.75 0 001.06-1.06l-1.59-1.591a.75.75 0 10-1.061 1.06l1.59 1.591zM12 18a.75.75 0 01.75.75V21a.75.75 0 01-1.5 0v-2.25A.75.75 0 0112 18zM7.758 17.303a.75.75 0 00-1.061-1.06l-1.591 1.59a.75.75 0 001.06 1.061l1.591-1.59zM6 12a.75.75 0 01-.75.75H3a.75.75 0 010-1.5h2.25A.75.75 0 016 12zM6.697 7.757a.75.75 0 001.06-1.06l-1.59-1.591a.75.75 0 00-1.061 1.06l1.59 1.591z"/>
                </svg>
            </button>
        </div>
    </nav>

    <div class="container">
        <div class="main-content">
            <div class="video-list">
                <h3><span>+</span>Videos</h3>
                <ul id="video-list"></ul>
            </div>
            <div class="video-player-container">
                <div class="video-title" id="video-title"></div>
                <video id="video-player" controls></video>
                <div class="loader" id="loader"></div>
            </div>
        </div>
    </div>

    <script>
        // 主题切换功能
        const themeToggle = document.getElementById('theme-toggle');
        const root = document.documentElement;
        const currentTheme = localStorage.getItem('theme') || 'light';

        // 设置初始主题
        root.setAttribute('data-theme', currentTheme);

        // 切换主题
        themeToggle.addEventListener('click', () => {
            const currentTheme = root.getAttribute('data-theme');
            const newTheme = currentTheme === 'light' ? 'dark' : 'light';
            root.setAttribute('data-theme', newTheme);
            localStorage.setItem('theme', newTheme);
        });

        const videoList = document.getElementById('video-list');
        const videoTitle = document.getElementById('video-title');
        const loader = document.getElementById('loader');

        // 获取视频列表
        const urlParams = new URLSearchParams(window.location.search);
        const folder = urlParams.get('folder') || '';
        fetch(`/videos?folder=${encodeURIComponent(folder)}`)
            .then(response => response.json())
            .then(videos => {
                videos.forEach(video => {
                    const li = document.createElement('li');
                    const a = document.createElement('a');
                    a.href = '#';
                    a.textContent = video.name;
                    a.onclick = (e) => {
                        e.preventDefault();
                        playVideo(video);
                    };
                    li.appendChild(a);
                    videoList.appendChild(li);
                });
            })
            .catch(error => {
                console.error('Error fetching videos:', error);
            });

        function playVideo(video) {
            videoTitle.textContent = video.name;
            loader.style.display = 'block';

            const videoPlayer = document.getElementById('video-player');
            videoPlayer.src = `/videos/${video.id}`;
            videoPlayer.play().catch(() => {
                alert('Failed to load video.');
                loader.style.display = 'none';
            });
            loader.style.display = 'none';
        }
    </script>
</body>
</html>
